/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.jm.financeiro.datamodel;

import br.jm.financeiro.entity.Cliente;
import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author joao
 */
public class LazySelectedClassificao extends ListDataModel<Cliente> implements SelectableDataModel<Cliente>, Serializable { 

    public LazySelectedClassificao() {
        
    }
    
    public LazySelectedClassificao(List<Cliente> data) {
        super(data);
    }
    
    @Override
    public Cliente getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        List<Cliente> clientes = (List<Cliente>) getWrappedData();
        
        for(Cliente cliente : clientes) {
            if(cliente.getIdCliente().toString().equals(rowKey))
                return cliente;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(Cliente cliente) {
        return cliente.getNomCliente();
    }
}
